package com.letoo.sso.core.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.letoo.sso.common.domain.Result;
import com.letoo.sso.common.domain.ResultCode;
import com.letoo.sso.common.utils.AssertUtil;
import com.letoo.sso.core.service.AppReleaseService;
import com.letoo.sso.dataaccess.dao.db.AppReleaseDBDAO;
import com.letoo.sso.dataaccess.dao.db.BaseDBDAO;
import com.letoo.sso.dataaccess.domain.dbo.AppReleaseDO;

/**
 * AppReleaseService接口实现
 * 
 * @author: dengjie
 */
@Service("appReleaseService")
public class AppReleaseServiceImpl extends BaseServiceImpl<AppReleaseDO> implements AppReleaseService {

	@Resource
	private AppReleaseDBDAO appReleaseDBDAO;

	@Override
	protected BaseDBDAO<AppReleaseDO> getDAO() {
		return appReleaseDBDAO;
	}

	@Override
	public Result queryAppRelease(final int type, final int appTypeId, final String appVersion) {
		AssertUtil.isNotBlank(appVersion, "appVersion is blank");
		AssertUtil.gt(appTypeId, 0, "appTypeId must gt zero");
		AppReleaseDO appReleaseDO = appReleaseDBDAO.queryAppRelease(type, appTypeId, appVersion);
		AssertUtil.notNull(appReleaseDO, "appReleaseDO must be not null");
		Result result = new Result(ResultCode.COMMON_SUCCESS, true);
		result.setProperty("upgrade", appReleaseDO.getUpgrade());
		result.setProperty("isForceUpgrade", appReleaseDO.getIsForceUpgrade());
		result.setProperty("updateLog", appReleaseDO.getUpdateLog());
		result.setProperty("updateUrl", appReleaseDO.getUpdateUrl());
		result.setProperty("isVerifyed", appReleaseDO.getIsVerifyed());
		result.setProperty("adsenseUrl", appReleaseDO.getAdsenseUrl());
		result.setProperty("adsenseTime", appReleaseDO.getAdsenseTime());
		result.setProperty("isEnableActivities", appReleaseDO.getIsEnableActivities());
		return result;
	}

}
